from prettytable import PrettyTable
import pandas as pd

# 创建 PrettyTable 对象
table = PrettyTable()

# 定义表头
table.field_names = ["学号", "姓名", "年龄", "性别"]

# 添加数据行
table.add_row(["001", "李磊", 16, "男"])
table.add_row(["002", "韩梅梅", 17, "女"])
table.add_row(["003", "Tom", 15, "男"])

# 提取 PrettyTable 数据
data = []
for row in table.rows:
    data.append(row)

# 将数据转换为 DataFrame
df = pd.DataFrame(data, columns=table.field_names)

# 导出到 Excel 文件
df.to_excel("output.xlsx", index=False)

print("表格已保存为 output.xlsx")